﻿using System;
using System.Security.Principal;
using System.Collections;
using System.Web;

namespace NWebMock
{
    public interface IHttpContext : IServiceProvider
    {
        #region Properties

        /// <summary>
        /// Gets an array of errors accumulated while processing an HTTP request.
        /// </summary>
        Exception[] AllErrors { get; }

        /// <summary>
        /// Gets the HttpApplicationState object for the current HTTP request.
        /// </summary>
        IHttpApplicationState Application { get; }

        /// <summary>
        /// Gets or sets the HttpApplication object for the current HTTP request.
        /// </summary>
        IHttpApplication ApplicationInstance { get; }

        /// <summary>
        /// Gets the Cache object for the current application domain.
        /// </summary>
        ICache Cache { get; }

        /// <summary>
        /// Gets the IHttpHandler object that represents the currently executing handler.
        /// </summary>
        IHttpHandler CurrentHandler { get; }

        /// <summary>
        ///  Gets a RequestNotification value that indicates the current HttpApplication event that is processing.  
        /// </summary>
        RequestNotification CurrentNotification { get; }

        /// <summary>
        /// Gets the first error (if any) accumulated during HTTP request processing.
        /// </summary>
        Exception Error { get; }

        /// <summary>
        /// Gets or sets the IHttpHandler object responsible for processing the HTTP request.
        /// </summary>
        IHttpHandler Handler { get; set; }

        /// <summary>
        /// Gets a value indicating whether custom errors are enabled for the current HTTP request.
        /// </summary>
        bool IsCustomErrorEnabled { get; }

        /// <summary>
        /// Gets a value indicating whether the current HTTP request is in debug mode.
        /// </summary>
        bool IsDebuggingEnabled { get; }

        /// <summary>
        /// Gets a value that is the current processing point in the ASP.NET pipeline just after an HttpApplication event has finished processing. 
        /// </summary>
        bool IsPostNotification { get; }

        /// <summary>
        /// Gets a key/value collection that can be used to organize and share data between an IHttpModule interface and an IHttpHandler interface during an HTTP request.
        /// </summary>
        IDictionary Items { get; }

        /// <summary>
        /// Gets the IHttpHandler object for the parent handler.
        /// </summary>
        IHttpHandler PreviousHandler { get; }

        /// <summary>
        /// Gets the ProfileBase object for the current user profile.
        /// </summary>
        IProfileBase Profile { get; }

        /// <summary>
        /// Gets the HttpRequest object for the current HTTP request.
        /// </summary>
        IHttpRequest Request { get; }

        /// <summary>
        /// Gets the HttpResponse object for the current HTTP response.
        /// </summary>
        IHttpResponse Response { get; }

        /// <summary>
        /// Gets the HttpServerUtility object that provides methods used in processing Web requests.
        /// </summary>
        IHttpServerUtility Server { get; }

        /// <summary>
        /// Gets the HttpSessionState object for the current HTTP request.
        /// </summary>
        IHttpSessionState Session { get; }

        /// <summary>
        /// Gets or sets a value that specifies whether the UrlAuthorizationModule object should skip the authorization check for the current request.
        /// </summary>
        bool SkipAuthorization { get; set; }

        /// <summary>
        /// Gets the initial timestamp of the current HTTP request.
        /// </summary>
        DateTime Timestamp { get; }

        /// <summary>
        /// Gets the TraceContext object for the current HTTP response.
        /// </summary>
        ITraceContext Trace { get; }

        /// <summary>
        /// Gets or sets security information for the current HTTP request.
        /// </summary>
        IPrincipal User { get; set; }

        #endregion

        #region Methods

        /// <summary>
        /// Adds an exception to the exception collection for the current HTTP request.
        /// </summary>
        /// <param name="errorInfo">The Exception to add to the exception collection.</param>
        void AddError(Exception errorInfo);

        /// <summary>
        /// Clears all errors for the current HTTP request.
        /// </summary>
        void ClearError();

        /// <summary>
        /// Returns requested configuration information for the current HTTP request.
        /// </summary>
        /// <param name="name">The configuration tag for which information is requested.</param>
        /// <returns>The specified ConfigurationSection, null if the section does not exist, or an internal object if the section is not accessible at run time.</returns>
        Object GetConfig(string name);

        /// <summary>
        /// Gets a specified configuration section for the current application's default configuration. 
        /// </summary>
        /// <param name="sectionName">The configuration section path (in XPath format) and the configuration element name.</param>
        /// <returns>The specified ConfigurationSection, null if the section does not exist, or an internal object if the section is not accessible at run time.</returns>
        Object GetSection(string sectionName);

        /// <summary>
        /// Enables you to specify a handler for the request.
        /// </summary>
        /// <param name="handler">The object that should process the request.</param>
        void RemapHandler(IHttpHandler handler);

        /// <summary>
        /// Rewrites the URL using the given path.
        /// </summary>
        /// <param name="path">The internal rewrite path.</param>
        void RewritePath(string path);

        /// <summary>
        /// Rewrites the URL using the given path and a Boolean value that specifies whether the virtual path for server resources is modified.
        /// </summary>
        /// <param name="path">The internal rewrite path.</param>
        /// <param name="rebaseClientPath">true to reset the virtual path; false to keep the virtual path unchanged.</param>
        void RewritePath(string path, bool rebaseClientPath);

        /// <summary>
        /// Rewrites the URL by using the given path, path information, and query string information.
        /// </summary>
        /// <param name="filePath">The internal rewrite path.</param>
        /// <param name="pathInfo">Additional path information for a resource.</param>
        /// <param name="queryString">The request query string.</param>
        void RewritePath(string filePath, string pathInfo, string queryString);

        /// <summary>
        /// Rewrites the URL using the given virtual path, path information, query string information, and a Boolean value that specifies whether the client file path is set to the rewrite path.
        /// </summary>
        /// <param name="filePath">The virtual path to the resource that services the request.</param>
        /// <param name="pathInfo">Additional path information to use for the URL redirect.</param>
        /// <param name="queryString">The request query string to use for the URL redirect.</param>
        /// <param name="setClientFilePath">true to set the file path used for client resources to the value of the filePath parameter; otherwise false.</param>
        void RewritePath(string filePath, string pathInfo, string queryString, bool setClientFilePath);

        #endregion
    }
}
